package com.shkmall.goods.controller;


import com.shkmall.common.pojo.Result;
import com.shkmall.common.pojo.StatusCode;
import com.shkmall.goods.dto.GoodsDto;
import com.shkmall.goods.service.SpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.ResultSet;

@RestController
@RequestMapping("/goods")
public class SpuController {
    @Autowired
    private SpuService spuService;

    @PostMapping("/add")
    public Result add(@RequestBody GoodsDto goodsDto){

    spuService.add(goodsDto);
    return new Result(true, StatusCode.OK,"添加成功");
    }

    /*根据id查询商品*/
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable("id") Integer id){
        GoodsDto data = spuService.findById(id);
        return new Result(true,StatusCode.OK,"查询成功",data);
    }
    /*修改商品*/
    @PutMapping("/update/{id}")
    public Result update(@PathVariable("id") String id,@RequestBody GoodsDto goodsDto){
        spuService.update(id,goodsDto);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /*审核*/
    @PutMapping("/review/{id}")
    public Result Review(@PathVariable("id") String id){
        spuService.review(id);
        return new Result(true,StatusCode.OK,"商品已审核");
    }

    /*上架*/
    @PutMapping("/put/{id}")
    public Result put(@PathVariable("id") String id){
        spuService.put(id);
        return new Result(true,StatusCode.OK,"商品上架成功");
    }


    /*下架*/
    @PutMapping("/off/{id}")
    public Result off(@PathVariable("id") String id){
        spuService.off(id);
        return new Result(true,StatusCode.OK,"商品下架成功");
    }

    /*逻辑删除*/
    @PutMapping("/deleteLogic/{id}")
    public Result deleteLogic(@PathVariable("id") String id){
        spuService.deleteLogic(id);
        return new Result(true,StatusCode.OK,"商品删除成功");
    }
    /*还原*/
    @PutMapping("/reduction/{id}")
    public Result reduction(@PathVariable("id") String id){
        spuService.reduction(id);
        return new Result(true,StatusCode.OK,"商品还原成功");
    }
    /*删除*/
    @PutMapping("/delete/{id}")
    public Result delete(@PathVariable("id") String id){
        spuService.delete(id);
        return new Result(true,StatusCode.OK,"商品删除成功");
    }
}
